package com.gopay.common.cps.dao.cbrmb.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.cbrmb.CbRmbAccountCapitalDtlDao;
import com.gopay.common.domain.cbrmb.CbRmbAccountCapitalDtl;

@Repository(value = "cbRmbAccountCapitalDtlDao")
public class CbRmbAccountCapitalDtlDaoImpl extends BaseDAOImpl<CbRmbAccountCapitalDtl, Serializable>
        implements CbRmbAccountCapitalDtlDao {

    @Override
    public List<CbRmbAccountCapitalDtl> getAccountCapitalDtlByOrderId(String orderId) {
        // TODO Auto-generated method stub
        String hql = " select m from CbRmbAccountCapitalDtl m where m.gopayOrderId = '"
                + orderId + "'";
        List<CbRmbAccountCapitalDtl> ss = findByHql(hql);
        return ss;
        
    }
    
    @Override
    public List<CbRmbAccountCapitalDtl> findByOrderIdAndOpt(String orderId, String opt) throws Exception {
        String hql = "from CbRmbAccountCapitalDtl where gopayOrderId = :orderId and capitalOpt = :opt";
        @SuppressWarnings("unchecked")
        List<CbRmbAccountCapitalDtl> dtls = super.getHibernateTemplate().findByNamedParam(hql, new String[]{"orderId","opt"}, new Object[]{orderId,opt});
        return dtls;
    }

    @Override
    public CbRmbAccountCapitalDtl findByOrderIdAndOptAndSource(String orderId, String opt, String source)
            throws Exception {
        String hql = "from CbRmbAccountCapitalDtl where gopayOrderId = :orderId and capitalSource = :source and capitalOpt = :opt";
        @SuppressWarnings("unchecked")
        List<CbRmbAccountCapitalDtl> dtls = super.getHibernateTemplate().findByNamedParam(hql, new String[]{"orderId","source","opt"}, new Object[]{orderId,source,opt});
        if (dtls != null && dtls.size() > 0) {
            return dtls.get(0);
        }
        return null;
    }

}
